#!/bin/bash

####### A test script for the programs. #########

N_EXECS=10 		# number of times to execute each input
OUTPUTS=./outputs/cuda	# directory for outputs
SMOOTH_MAX=5		# maximum K for K changing analisys
SMOOTH_DEFAULT=5	# default K value
INPUTS=./inputs	# input directory
N_INPUTS=2		# number of inputs in directory

printf '\n'
echo "Running script test for $N_INPUTS files in $INPUTS directory..."
printf '\n'

for ((i = 1; i <= $N_INPUTS; i++))
do 
	INPUT=input$i
	OUT=$OUTPUTS/$INPUT
	IN=$INPUTS/$INPUT

	mkdir $OUT

# running sequential
	echo "$INPUT >>>"
	echo "Running sequential program $N_EXECS times with SMOOTH_SQUARE_SIDE = 5..."
	for ((j = 1; j <= $N_EXECS; j++))
	do
		echo "$j..."
		/usr/bin/time -o $OUT/seq.times -a -f "%e" ./build/seq $IN $OUT/seq $SMOOTH_DEFAULT >> $OUT/seq.out
	done

# running CUDA for fixed SQUARE = 5
	printf '\n'
	echo "Running CUDA program $N_EXECS times with SMOOTH_SQUARE_SIDE = 5..."
	for ((j = 1; j <= $N_EXECS; j++))
	do
		echo "$j..."
		/usr/bin/time -o $OUT/cuda.times -a -f "%e" ./build/cuda $IN $OUT/cuda $SMOOTH_DEFAULT >> $OUT/cuda.out
	done

# running sequential - CHANGING SQUARE_SIDE
	printf '\n'
	echo "Running sequential program for differents SMOOTH_SQUARE_SIDE..(3, 5, 7, ..., $SMOOTH_MAX)..."
	for ((j = 5; j <= $SMOOTH_MAX; j += 4))
	do
		echo "smooth_side = $j.." 
		/usr/bin/time -o $OUT/seq-smooth.times -a -f "%e" ./build/seq $IN $OUT/seq-smooth $j >> $OUT/seq-smooth.out
	done

# running CUDA - CHANGING SQUARE_SIDE
	printf '\n'
	echo "Running CUDA program for differents SMOOTH_SQUARE_SIDE..(3, 5, 7, ..., $SMOOTH_MAX)..."
	for ((j = 5; j <= $SMOOTH_MAX; j += 4))
	do
		echo "smooth_side = $j.." 
		/usr/bin/time -o $OUT/cuda-smooth.times -a -f "%e" ./build/cuda $IN $OUT/cuda-smooth $j >> $OUT/cuda-smooth.out
	done

# IO test
	printf '\n'
	echo "Running test I/O"
	for ((j = 1; j <= 5; j++))
	do
		echo "$j..."
		/usr/bin/time -o $OUT/io_test.times -a -f "%e" ./build/io_test $IN $OUT/io_test_exit 
	done

	printf '\n\n'
done
